<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>添加联系人</title>
<style type="text/css">
.STYLE6 {
color:#FFFFFF;
font-size:13px;
}
.STYLE7 {
color:#336699;
font-family:"Arial","宋体";
font-size:12px;
line-height:130%;
}
</style>
<script src="js/jquery.js"></script>
<script src="js/public.js"></script>
<script type="text/javascript" >
var button=[true,true];
$(document).ready(function(){ 
	$.post("getGroupByUserId",function(data){
		if (data == "" || data == null) {
			return;
		}
		var groups = new Array();
		groups = getModelArray(data);
		for (var i = 0; i < groups.length; i++) {
			var group = groups[i];
			var select;
			if(i==0){
				select = $('<option selected="selected"/>');
			}else{
				select = $('<option/>');
			}
			select.attr("value",group.groupId);
			select.html(group.groupName);
			select.appendTo($("#groupId"));
		}
	},"text")
	
	if(parent.tmpId!=0){
		$.post("getContactByContactId",{'contactId':parent.tmpId},function(data){
			var contacts = new Array();
			contacts = getModelArray(data);
			var contact=contacts[0];
			$("#contactId").val(contact.contactId);
			$("#firstName").val(contact.firstName);
			$("#secondName").val(contact.secondName);
			$("#mobilePhone").val(contact.mobilePhone);
			$("#officePhone").val(contact.officePhone);
			$("#homePhone").val(contact.homePhone);
			$("#email").val(contact.email);
			$("#QQ").val(contact.QQ);
			$("#MSN").val(contact.MSN);
			$("#address").val(contact.address);
			$("#describe").val(contact.describe);
			$('input[name="contact.sex"][value="'+contact.sex+'"]').attr("checked","checked");
			$('option:contains("'+contact.groupName+'")').attr("selected","selected");
			$("#submit").replaceWith('<input type="button" id="submit" value="提交" onclick="modContact()"/>');
			parent.tmpId=0;
		},"text")
	}
}); 
function modContact(){
	$.post("modContact",
		{'contact.contactId':$("#contactId").val(),
		'contact.firstName':$("#firstName").val(),
		'contact.sex':$("input[name=contact.sex][checked]").val(),
		'contact.secondName':$("#secondName").val(),
		'contact.groupId':$("#groupId").val(),
		'contact.sex':$("input[name=contact.sex][checked]").val(),
		'contact.mobilePhone':$("#mobilePhone").val(),
		'contact.officePhone':$("#officePhone").val(),
		'contact.homePhone':$("#homePhone").val(),
		'contact.email':$("#email").val(),
		'contact.QQ':$("#QQ").val(),
		'contact.MSN':$("#MSN").val(),
		'contact.address':$("#address").val(),
		'contact.describe':$("#describe").val()},
		function(data){
			if(data=="true"){
				window.parent.getContact(0);
				window.parent.show_Message("修改联系人信息成功!","green");
				window.parent.tb_remove();
			}else{
				window.parent.getContact(0);
				window.parent.show_Message("修改联系人信息失败,请稍后再试!","red");
				window.parent.tb_remove();
			}
		},
	"text")
}

function addContact(){
	$.post("addContact",
		{'contact.firstName':$("#firstName").val(),
		'contact.sex':$("input[name=contact.sex][checked]").val(),
		'contact.secondName':$("#secondName").val(),
		'contact.groupId':$("#groupId").val(),
		'contact.sex':$("input[name=contact.sex][checked]").val(),
		'contact.mobilePhone':$("#mobilePhone").val(),
		'contact.officePhone':$("#officePhone").val(),
		'contact.homePhone':$("#homePhone").val(),
		'contact.email':$("#email").val(),
		'contact.QQ':$("#QQ").val(),
		'contact.MSN':$("#MSN").val(),
		'contact.address':$("#address").val(),
		'contact.describe':$("#describe").val()},
		function(data){
			if(data=="true"){
				window.parent.getContact(0);
				window.parent.show_Message("添加联系人成功!","green");
				window.parent.tb_remove();
			}else{
				window.parent.getContact(0);
				window.parent.show_Message("添加联系人失败,请稍后再试!","red");
				window.parent.tb_remove();
			}
		},
	"text")
}
function checkFirstName(){
	var reg=/[\u4e00-\u9fa5a-zA-Z]/;
	var firstName = trim($("#firstName").val());
	if(/^[a-zA-Z ]{1,20}$/.test(firstName)||/^[\u4e00-\u9fa5]{1,10}$/.test(firstName)){
		$("#font1").attr("color","green");
		$("#font1").html("<img src=\"images/check_right.gif\"/>");
		buttoncheck(0,true);
	}else{
		$("#font1").attr("color","red");
		$("#font1").html("<img src=\"images/check_error.gif\"/>&nbsp;请输入正确的联系人的姓氏");
		buttoncheck(0,false);
	}
}

function checkSecondName(){
	var reg=/[\u4e00-\u9fa5a-zA-Z]/;
	var secondName = trim($("#secondName").val());
	if(/^[a-zA-Z ]{1,20}$/.test(secondName)||/^[\u4e00-\u9fa5]{1,10}$/.test(secondName)){
		$("#font2").attr("color","green");
		$("#font2").html("<img src=\"images/check_right.gif\"/>");
		buttoncheck(1,true);
	}else{
		$("#font2").attr("color","red");
		$("#font2").html("<img src=\"images/check_error.gif\"/>&nbsp;请输入正确的联系人的名字");
		buttoncheck(1,false);
	}
}
function buttoncheck(index,bool){
	button[index]=bool;
	if(bool){
		for(var i=0;i<button.length;i++){
			if(!button[i]){
				return;
			}
		}
		document.getElementById("submit").disabled=false;
	}else{
		document.getElementById("submit").disabled=true;
	}
}
</script> 
<style type="text/css">
<!--
body {
	background-image: url(images/bg2.gif);
	background-repeat: repeat;
}
-->
</style></head>
<body>
	<table width="600" border="1" align="center" >
    <tr>
        <td align="right" width="17%" bgcolor="#1e84b4" class="STYLE6">姓氏：</td>
        <td width="33%"><input type="text" id="firstName" name="contact.firstName" onKeyUp="checkFirstName()" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" width="50%"><font id="font1" size="2" color="#808080">请输入联系人的姓氏,1-20个字母或者1-10个汉字</font></td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">名：</td>
        <td ><input type="text" id="secondName" name="contact.secondName" onKeyUp="checkSecondName()" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left"><font id="font2" size="2" color="#808080">请输入联系人的名字,1-20个字母或者1-10个汉字</font></td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">选择分组：</td>
        <td ><select name="contact.groupId" id="groupId"></select></td>
        <td align="left" >&nbsp;</td>
    </tr>
	
	 <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">性别：</td>
        <td class="STYLE7">
        	<input type="radio" id="sex1" name="contact.sex" value="男" bgcolor="#FFFFFF" class="STYLE7"  checked="checked"/>男&nbsp;&nbsp;
        	<input type="radio" id="sex2" name="contact.sex" value="女" bgcolor="#FFFFFF" class="STYLE7"/>女
        </td>
        <td align="left" >&nbsp;</td>
    </tr>
    <tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">手机号：</td>
        <td ><input type="text" id="mobilePhone" name="contact.mobilePhone" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" >&nbsp;</td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6" >办公电话：</td>
        <td ><input type="text" id="officePhone" name="contact.officePhone" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" >&nbsp;</td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">家庭电话：</td>
        <td ><input type="text" id="homePhone" name="contact.homePhone" bgcolor="#FFFFFF" class="STYLE7"></input> </td>
        <td align="left">&nbsp;</td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">e-mail：</td>
        <td ><input type="text" id="email" name="contact.email" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" >&nbsp;</td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">QQ：</td>
        <td ><input type="text" id="QQ" name="contact.QQ" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" >&nbsp;</td>
    </tr>
   
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">MSN：	</td>
        <td><input type="text" id="MSN" name="contact.MSN" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left">&nbsp;</td>
    </tr>
    <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">地址：</td>
        <td ><input type="text" id="address" name="contact.address" bgcolor="#FFFFFF" class="STYLE7"></input></td>
        <td align="left" >&nbsp;</td>
    </tr>
   
     <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">描述：</td>
        <td><textarea id="describe" name="contact.describe" style="height:40px;width:170px" bgcolor="#FFFFFF" class="STYLE7"></textarea></td>
        <td>&nbsp;</td>
    </tr>
    <tr >
        <td colspan="2" align="center" >
        	<input type="button" id="submit" value="提交" disabled="true" onClick="addContact()"/>&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="reset" value="重置">
        </td>
		<td ><input type="hidden" id="contactId" valu="" /></td> 
    </tr>
</table>

</body>
</html>